package num104;

import com.sun.source.tree.NewArrayTree;
import num49.Solution;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/5/8 22:45
 * @Desc :
 */
public class Solution2 {
  private int maxDepth = 0;

  public int maxDepth(TreeNode root) {
    recursion(root, 0);
    return maxDepth;
  }

  public void recursion(TreeNode root, int n) {
    if (root == null) return;
    maxDepth = Math.max(n + 1, maxDepth);
    recursion(root.left, n + 1);
    recursion(root.right, n + 1);
  }

  public static void main(String[] args) {
    TreeNode head = new TreeNode(3);
    head.left = new TreeNode(9);
    head.right = new TreeNode(20);
    head.right.left = new TreeNode(15);
    head.right.right = new TreeNode(7);

    int res = new Solution2().maxDepth(head);
    System.out.println(res);
  }
}
